package cn.jdy.uum.service;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.jdy.framework.db.hibernate.BaseDao;
import cn.jdy.uum.entity.Person;

@Repository
public class PersonService extends BaseDao<Person>{

  /**
   * 非分页情况下
   * @return
   */
	public List<Person> getPeople() {
	  String sql = "select age,birday,sex from Person p where age=? and sex=?";
	  List<Person> list = (List<Person>) hibernateTemplate.find(sql, new Object[]{"26",0});
	  return list;
	}
	
	/**
	 * 分页情况下
	 * @return
	 */
	@SuppressWarnings("unchecked")
  public List<Person> getPeople2() {
		return em().createSQLQuery("select age,birday,sex from Person p where age=? and sex=?")
		    .setParameter(0, "26")
		    .setParameter(1, 0)
		    .setFirstResult(0)
		    .setMaxResults(10)
		    .list();
	}
	
	// 在下面写 父类 搞不定的代码
	
//	@Transactional
//	public Person save(Person person) {
//		if (person.getId() == null) {
//			entityManager.persist(person);
//			return person;
//		} else {
//			return entityManager.merge(person);
//		}		
//	}
	
 
	
}
